var process = require('child_process');

change_screencapture_format('png');

/*
 * Support format as:png (default)、pdf、jpg、jp2 (JPG2000)、gif、tif
 * (TIFF)、bmp、pict、tga
 */
function change_screencapture_format(picFormat) {
	if (!picFormat) {
		picFormat = "png";
	}
	var command = 'defaults write com.apple.screencapture type ' + picFormat;
	exeCommand(command);
}

function change_screencapture_location(path) {
	if (!path) {
		path = "~/Desktop/pics";
	}
	var command = 'defaults write com.apple.screencapture location ' + path;
	command += ' && killall SystemUIServer';
	exeCommand(command);
}

/*
 * true will show all files and vice-versa.
 */
function toggle_file_visibility(isDisplay) {
	var isDisplayStr = isDisplay ? "true" : "false";
	var command = "defaults write com.apple.finder AppleShowAllFiles -bool "
			+ isDisplayStr + " && killall Finder";
	exeCommand(command);
}

/*
 * yes will show dashboard and vice-versa.
 */
function toggle_dashboard_visibility(isDisplay) {
	var isDisplayStr = isDisplay ? "yes" : "no";
	var command = "defaults write com.apple.dashboard mcx-disabled -boolean "
			+ isDisplayStr + " && killall Dock";
	exeCommand(command);
}

function exeCommand(command) {
	process.exec(command);
}